'use strict';
app.service('homeService',['$http','$q','utilService',function($http,$q,utilService){

    this.find= function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'home/terrace/header',
            data:$scope.statistics
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    this.queryOrdersInfo=function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'home/all/orders',
            params:{'year':$scope.ordersYears,'month':$scope.ordersMonth}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        })

        return deferred.promise;
    }

    this.queryInternalNotice= function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'home/notice'
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        })

        return deferred.promise;
    }

    this.queryFlowHistory= function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'home/flow',
            params:{'year':$scope.flowYears,'month':$scope.flowMonth}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        })

        return deferred.promise;
    }
}]);